package com.zzti.serviceImpl;


import com.zzti.mapper.OrderEquMapper;
import com.zzti.pojo.OrderEqu;
import com.zzti.service.OrderEquService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;


@Service
public class OrderEquServiceImpl implements OrderEquService {

    @Autowired
    private OrderEquMapper orderEquMapper;

    @Override
    public int[] selectByTime() {
        int[] arr = new int[12];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = 0;
        }
        List<OrderEqu> ls = orderEquMapper.selectByTime();
        System.out.println(ls);
        for (OrderEqu or : ls) {
            int hours = or.getCreateTime().getHours();
            arr[hours / 2]++;
        }
        return arr;
    }

    @Override
    public Integer add(Integer visiterId, String address, Integer equipmentId) {
        OrderEqu oe = new OrderEqu();
        oe.setVisiterId(visiterId);
        oe.setEquId(equipmentId);
        oe.setDamage(1);
        Date date = new Date();
        oe.setCreateTime(date);
        if (address != null && address != "")
            oe.setAddress(address);
        System.out.println(oe.toString());
        return orderEquMapper.insert(oe);
    }

    @Override
    public OrderEqu findOne(Integer equId) {
        return orderEquMapper.selectById(equId);
    }


    @Override
    public List<OrderEqu> slectAll() {
        return orderEquMapper.selectAll();
    }

    @Override
    public List<OrderEqu> slectList(Map map) {
        return orderEquMapper.selectList(map);
    }

    @Override
    public Integer updateState(String id) {
        return orderEquMapper.updateState(id);
    }

    @Override
    public Integer updateDamage(String id) {
        return orderEquMapper.updateDamage(id);
    }

    @Override
    public Integer deleteByIds(Integer[] ids) {
        List<Integer> lids = Arrays.asList(ids);
        return orderEquMapper.deleteBatchIds(lids);
    }

    @Override
    public List<Map<String, Integer>> contOneMonthEqu() {
        return orderEquMapper.contOneMonthEqu();
    }

}
